package main.userInterface.critterui.critterviewer;

import java.awt.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * User: gabe
 * Date: 18/07/13
 * Time: 18:49
 * To change this template use File | Settings | File Templates.
 */
public class Drawing {

    public ArrayList<LinePoint> points = new ArrayList<LinePoint>();

    public LinePoint current = new LinePoint();

    public void addToCurrent(Point a){
        current.add(a);

        if(current.isComplete()){
            points.add(current);
            current = new LinePoint();
            current.add(a);
        }
    }


    String brok = "},\n {";
    String bra = " , ";

    public void save(){
        try {
            File file = new File("points.txt");

            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));

            bufferedWriter.write("{{"+points.get(0).getX().x + bra + points.get(0).getX().y );

            for(LinePoint point : points){

                bufferedWriter.write(brok +
                        point.getY().x + bra + point.getY().y  + bra +
                        point.getArc().x + bra + point.getArc().y);
            }

            bufferedWriter.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public class LinePoint{
        private Point x, y, arc;

        int progress = 0;

        public boolean isComplete(){
            if( progress > 2) return true;
            else return false;
        }

        public void add(Point a){

            if(progress == 0) x = a;
            else if (progress == 1) y = a;
            else if (progress == 2) arc = a;

            progress++;
        }

        public Point getX() {
            if(progress<1) return null;

            return x;
        }

        public Point getY() {
            if(progress<2) return null;

            return y;
        }

        public Point getArc() {
            if(progress<3) return null;

            return arc;
        }

    }


}
